#include <iostream>
#include <cmath>

using namespace std;

class Solution {
public:
    string intToRoman(int num) 
    {
        string str = specital(num);
        if (str != "") {
            return str;
        }
        const string rom10 = "IXCM";
        const string rom5 = "VLD";

        int tmpCount, devided10, devided5;

        for (int counter = 3; counter >= 0 && num > 0; --counter) {
            devided10 = pow(10, counter);
            tmpCount = num / devided10;
            str.append(tmpCount, rom10[counter]);
            num %= devided10;

            // 看能不能用900， 90， 9表示
            str.append(Is900(num));

            if (counter == 0) {
                break;
            }

            devided5 = 5 * pow(10, counter - 1);
            if (num - devided5 >= 0) {
                num -= devided5;
                str.push_back(rom5[counter - 1]);
            }

            // 看能不能用400， 40， 4表示
            str.append(Is400(num));
        }
        return str;
        
    }
private:
    string Is400(int &num)
    {
        if (num >= 400 && num < 500) {
            num -= 400;
            return "CD";
        }

        if (num >= 40 && num < 50) {
            num -= 40;
            return "XL";
        }

        if (num == 4) {
            num -= 4;
            return "IV";
        }
        return "";
    }

    string Is900(int &num)
    {
        if (num >= 900 && num < 1000) {
            num -= 900;
            return "CM";
        }

        if (num >= 90 && num < 100) {
            num -= 90;
            return "XC";
        }

        if (num == 9) {
            num -= 9;
            return "IX";
        }
        return "";
    }

    string specital(int num) 
    {
        switch (num) {
            case 4:
                return "IV";
            case 9:
                return "IX";
            case 40:
                return "XL";
            case 90:
                return "XC";
            case 400:
                return "CD";
            case 900:
                return "CM";
            default:
                return "";
        }
    }
};

int main()
{
    Solution sol;
    int i;
    while(cin>>i)
        cout<<sol.intToRoman(i)<<endl;
    return 0;
}